package com.robot.util;

import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/12/1
 * Time: 13:55
 * PROJECT：robot
 * PACKAGE: com.robot
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
@Component
public class DateUtil {

    public static final String YMD_HMS="yyyy-MM-dd HH:mm:ss";

    public static final String YMD="yyyy-MM-dd";
    /**
     * 获取当前的时间,默认是带时分秒的
     *
     * **/
    public String getCurrentTime(){
      return format(new Date(),YMD_HMS);
    }
    /**
     * 获取当前的时间,自定义时间格式
     *
     * **/
    public String getCurrentTime(String pattern){
        return format(new Date(),pattern);
    }
    private String format(Date date,String pattern){
        DateFormat dateFormat =new SimpleDateFormat(pattern);
       return dateFormat.format(date);
    }
}
